package com.dianrui.operation.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.dianrui.operation.R;
import com.dianrui.operation.bean.Datas;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FeedBackInfoAdapter extends BaseAdapter {
    private List<Datas> list;
    private Context context;


    public FeedBackInfoAdapter(Context context, List<Datas> list) {
        this.list = list;
        this.context = context;

    }

    public void refresh(List<Datas> list) {
        this.list = list;
        this.notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        if (list == null) {
            return 0;
        }
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView != null) {
            viewHolder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(context).inflate(R.layout.grid_info_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }
        if (null != list && list.size() > 0) {
            final Datas item = list.get(position);
            viewHolder.feed_name.setText(item.name);
            if (item.isChecked==1) {
                viewHolder.chooseImg.setVisibility(View.VISIBLE);
               viewHolder.feed_name.setTextColor(context.getResources().getColor(R.color.white));
            }
            if (item.isChecked==0) {
                viewHolder.chooseImg.setVisibility(View.INVISIBLE);
                viewHolder.feed_name.setTextColor(context.getResources().getColor(R.color.black));
            }


            }
        return convertView;
    }



    class ViewHolder {
        @BindView(R.id.feed_name)
        TextView feed_name;

        @BindView(R.id.choose_img)
        ImageView chooseImg;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
